package com.example.s.fragment;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;

import androidx.annotation.Nullable;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.example.s.Activity.MessageCommonActivity;
import com.example.s.Activity.team.TeamMessageActivity;
import com.example.s.R;
import com.example.s.adapter.InnerHolder;
import com.example.s.adapter.MyRecyclerViewAdapter;
import com.example.s.bean.MessageBean;

import java.util.ArrayList;
import java.util.List;

public class ChatFragment extends BaseFragment {
    private LinearLayout attention;
    private LinearLayout prise;
    private LinearLayout comment;
    private RecyclerView messageRv;
    private List<MessageBean> mMessageBeanList = new ArrayList<>();
    private MyRecyclerViewAdapter<MessageBean> mMessageAdapter;


    @Override
    public int getLayoutId() {
        return R.layout.fragment_chat;
    }

    @Override
    public void initView(View view) {

        attention = (LinearLayout) findViewById(R.id.attention);
        prise = (LinearLayout) findViewById(R.id.prise);
        comment = (LinearLayout) findViewById(R.id.comment);
        messageRv = (RecyclerView) findViewById(R.id.messageRv);
    }

    @Override
    public void onActivityCreated(@Nullable Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);

        attention.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(getActivity(), MessageCommonActivity.class);
                intent.putExtra("message_type",1);
                startActivityForResult(intent,201);
            }
        });

        prise.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(getActivity(), MessageCommonActivity.class);
                intent.putExtra("message_type",2);
                startActivityForResult(intent,202);
            }
        });

        comment.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                Intent intent = new Intent(getActivity(), MessageCommonActivity.class);
                intent.putExtra("message_type",3);
                startActivityForResult(intent,203);
            }
        });




        setMessageBeanData();
        messageRv.setLayoutManager(new LinearLayoutManager(getContext()));
        messageRv.setAdapter(mMessageAdapter = new MyRecyclerViewAdapter<MessageBean>(mMessageBeanList, R.layout.rv_message_item) {
            @Override
            public void handleData(InnerHolder holder, MessageBean item) {
                holder.setText(R.id.name, item.getmName());
                holder.setText(R.id.content, item.getmContent());
                holder.setText(R.id.time, item.getmTime());
                holder.setSrcResource(R.id.photo, item.getmPhoto());
                holder.setVisibility(R.id.unRead, !item.ismIsRead());
                TextView name = holder.getView(R.id.name);
                if("组队消息".contentEquals(name.getText())){
                    holder.setOnClickListener(R.id.item, new View.OnClickListener() {
                        @Override
                        public void onClick(View v) {
                            startActivityForResult(new Intent(getActivity(), TeamMessageActivity.class),204);
                        }
                    });
                }
            }
        });

    }

    private void setMessageBeanData() {
        //前四条固定
        mMessageBeanList.add(new MessageBean(R.mipmap.message_team, "组队消息", "alone请求加入组队", "3天前", false));
        mMessageBeanList.add(new MessageBean(R.mipmap.message_private_letter, "私信消息", "你拍的作品真不错！", "3天前", false));
        mMessageBeanList.add(new MessageBean(R.mipmap.message_push, "推送消息", "您的作品已被顶上首页", "3天前", true));
        mMessageBeanList.add(new MessageBean(R.mipmap.message_service, "客服消息", "请尽快完善您的信息", "3天前", true));
        mMessageBeanList.add(new MessageBean(R.drawable.yyw33, "扑通", "求一波关注", "1天前", true));


    }

}
